package com.uzhie.spring;

import com.uzhie.util.PayloadBeanUtil;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by TangFei on 2018/7/23.
 */
public class HttpRequestHolder {

    private ThreadLocal<HttpServletRequest> requestThreadLocal = new ThreadLocal<>();
    private static HttpRequestHolder instance;

    public HttpRequestHolder() {
    }

    public static HttpRequestHolder getInstance() {
        if (instance == null) {
            synchronized (PayloadBeanUtil.class) {
                if (instance == null) {
                    instance = new HttpRequestHolder();
                }
            }
        }
        return instance;
    }

    public void setRequest(HttpServletRequest request) {
        requestThreadLocal.set(request);
    }

    public HttpServletRequest getRequet() {
        return requestThreadLocal.get();
    }

}
